;Print hex integer.
extern put_char
global print_int

bits 32
print_int:
	pushad
	push ebp
	mov ebp, esp
	;Get argument from stack
	mov eax, [ebp+40]

	mov ecx, 7;8 hex numbers.Only print the first 7 numbers.
;Ignore the zeros at start.Every time check four bits, namely one hex.Register "eax" shifts left 4 bits to assure the number will be checked on the four highest bits.
.ignore_start_zero:
	mov ebx, eax
	and ebx, 0xf0000000
	cmp ebx, 0
	jz .not_print
;Print numbers from the first one which is not zero to end.
.print_num:
	mov ebx, eax
	and ebx, 0xf0000000
	shr ebx, 28
	cmp bl, 10
	jl .l10
	sub bl, 9;Ascii of number greater than 9
	add bl, 0x10
.l10:
	add bl, 0x30;Ascii of number less than or equal 9
	push ebx
	call put_char
	add esp, 4
	shl eax, 4
	loop .print_num
	jmp .end
.not_print:
	shl eax, 4
	dec ecx
	cmp ecx, 0
	jz .end
	jmp .ignore_start_zero

.end:;Print the last number.
	mov ebx, eax
	and ebx, 0xf0000000
	shr ebx, 28
	cmp bl, 10
	jl .l10_2
	sub bl, 9;Ascii of number greater than 9
	add bl, 0x10
.l10_2:
	add bl, 0x30;
	push ebx
	call put_char
	add esp, 4

	pop ebp
	popad
	ret


	


